package com.njwb.controller;

import com.njwb.feign.client.UserServiceClient;
import com.njwb.json.ResponseResult;
import com.njwb.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    @Autowired
    private UserServiceClient userServiceClient;
    @PostMapping("user")
    public ResponseResult add(User user){
        return userServiceClient.add(user.getUsername(),user.getPassword());
    }
    @DeleteMapping("user/{id}")
    public ResponseResult remove(@PathVariable("id") Integer id){
        return userServiceClient.delById(id);
    }
    @PutMapping("user")
    public ResponseResult modify(User user){
        return userServiceClient.modify(user.getId(),
                user.getUsername(),
                user.getPassword());
    }
    @GetMapping("user/{id}")
    public ResponseResult findById(@PathVariable("id") Integer id){
        return userServiceClient.findById(id);
    }
    @GetMapping("user")
    public ResponseResult findAll(){
        return userServiceClient.findAll();
    }
}